<?php

// Check to ensure this file is included in Joomla!

defined('_JEXEC') or die();

jimport( 'joomla.application.component.view');

class DetaiViewDanhsach_edit extends JView
{
	function display($tpl = null)
	{
		global $mainframe;
		
		$db		=& JFactory::getDBO();
		$uri 	=& JFactory::getURI();
		$model	=& $this->getModel();
		$document =& JFactory::getDocument();

		$item	=& $this->get('data');
		$isNew		= ($item->id < 1);
		if ($isNew)
		{
			$item->name  = 1;
			$item->published = 1;
			$item->donvi  = 0;
			$item->ma  = '';
			$item->catid  = 0;
			$item->thoigian_batdau = 0;
			$item->thoigian_ketthuc = 0;
			$item->chuongtrinh  = '';
			$item->chunhiem  = '';
			$item->canbo  = '';
			$item->kinhphi  = '';
			$item->muctieu  = '';
			$item->noidung  = '';
			$item->ketqua   = '';
			$item->donggop  = '';
			$item->sanpham  = '';
			$item->khuvuc  = '';
			$item->diachi  = '';
		}
		
		// list
		$lists = array();
		$lists['published'] = JHTML::_('select.booleanlist',  'published', 'class="inputbox"', $item->published );
		$lists['nghiemthu'] = JHTML::_('select.booleanlist',  'nghiemthu', 'class="inputbox"', $item->nghiemthu, 'Đã nghiệm thu', 'Chưa nghiệm thu' );
		
		// don vi
		$query = 'SELECT c.id AS value, c.name AS text '
			. ' FROM #__detai_donvi AS c'
			;
		$db->setQuery( $query );
		$htList[] = JHTML::_('select.option',  '0',JText::_( '--- Chọn Đơn vị thực hiện ---' ));
		$htList = array_merge( $htList, $db->loadObjectList() );		
		$lists['donvi'] = JHTML::_('select.genericlist', $htList,'donvi', 'class="inputbox"', 'value', 'text',$item->donvi);
		
		// danh muc
		$query = 'SELECT c.id AS value, c.name AS text '
			. ' FROM #__detai_category AS c'
			. ' WHERE c.published = 1'
			;
		$db->setQuery( $query );
		$catList[] = JHTML::_('select.option',  '0',JText::_( '--- Chọn hướng KHCN ---' ));
		$catList = array_merge( $catList, $db->loadObjectList() );		
		$lists['category'] = JHTML::_('select.genericlist', $catList,'catid', 'class="inputbox" ', 'value', 'text',$item->catid);		
				
		$this->assignRef('item',$item);
		$this->assignRef('lists',$lists);
		
		parent::display($tpl);
	}
	
	function buildList($min,$max,$name,$value)
	{
		//$option = array();
		for ($i=$min; $i<=$max; $i++) {
			$option[] = JHTML::_('select.option', $i,$i);
		}
		$list = JHTML::_('select.genericlist', $option,$name, 'class="inputbox" ', 'value', 'text',$value);		
		return $list;
	}
}
?>